#ifndef MESH_H
#define MESH_H

#include "EngineApi.h"
#include "Entity.h"
#include "BoundingBox.h"

typedef D3DMATERIAL9 Material;

class ENGINE_API Mesh : public Entity
{
public:
   Mesh(std::string name,
      unsigned short vertexCount, SuperVertex* vertices,
      unsigned short indexCount, unsigned int* indices,
      PRIM_TYPE primType, unsigned short primCount);
      
   ~Mesh()
   {
      delete m_pVertices;
      delete m_pIndices;
   }

   virtual void draw(Renderer* renderer);

   virtual void setMaterialDiffuse(float r, float g, float b, float a = 1)
   {
      m_material.Diffuse = D3DXCOLOR(r,g,b,a);
   }

   virtual void setMaterialAmbient(float r, float g, float b, float a = 1)
   {
      m_material.Ambient = D3DXCOLOR(r,g,b,a);
   }
   
   virtual void setMaterialEmissive(float r, float g, float b, float a = 1)
   {
      m_material.Emissive = D3DXCOLOR(r,g,b,a);
   }

   virtual void setMaterialSpecular(float r, float g, float b, float a = 1)
   {
      m_material.Specular = D3DXCOLOR(r,g,b,a);
   }

   virtual void setMaterialPower(float power)
   {
      m_material.Power = power;
   }

   bool setVertexUV( int index, float u, float v );
   void setVertexColor(int index, float r, float g, float b, float a = 1);
   void setTexture( Texture::TexturePtr texture ) { m_pTexture = texture; }

   virtual void update(float deltaTime){}
   
   virtual void onCollision(Entity* collider){}

   void setDefaultMaterial();

   SuperVertex* getVertices() const;
   size_t getNumVertices() const;

   
   BoundingBox* getBoundingBox() { return m_boundingBox; }


protected:
   SuperVertex* m_pVertices;
   unsigned int* m_pIndices;
   PRIM_TYPE m_primitiveType;

   size_t m_vertexCount;
   unsigned short m_indexCount;
   unsigned short m_primCount;

   Texture::TexturePtr m_pTexture;

   Material m_material;

   BoundingBox* m_boundingBox;

private:
   void createBoundingBox();
};

#endif//MESH_H 